package com.lx.test;

import java.util.Arrays;
import java.util.Comparator;

public class lamdademo {
    public static void main(String[] args) {
        String arr[] = {"a","aaaa","aa","aaa","aaaaa"};
        //内部类
        Arrays.sort(arr, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.length()-o2.length();
            }
        });
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
        //lamda表达式简写
        Arrays.sort(arr,((o1, o2) -> o2.length()-o1.length()));
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }

    }
}
